/**
 * @author hugh
 * @time  2021-01-10 11:40
 * @title  路由配置
 * @desc
 *
 */
import { createRouter, createWebHashHistory,createWebHistory, RouteRecordRaw } from 'vue-router'
import auth from './modules/auth';
const routes: Array<RouteRecordRaw> = [
  // 首页
  {
    path: '/',
    name: 'home',
    redirect: '/statistics',
    component: () => import('@/layouts/Index.vue'),
    children:[
      ...auth,
      /**
       *@title 数据统计
       *@author hugh
       *@date 2021-01-22
       */
      {
        path: '/statistics',
        component: () => import('@/views/auth/Index.vue'),
        name: 'statistics',
        meta: {
          title: 'Statistics',
          icon: 'edit'
        }
      }

    ]
  },
  /**
   *@title 登录
   *@author hugh
   *@date 2021-01-22
   */
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/account/Login.vue')
  }

]
/**
 * 创建路由
 * @param history 路由模式
 */
const router = createRouter({
  history: createWebHistory(),
  routes
})
/**
 * 动态添加路由
 * */
export function addRoutes(array:Array<RouteRecordRaw>) {
	array.forEach((item:RouteRecordRaw)=>{
    router.addRoute(item);
    router.options.routes.push(item);
  })
}
const routesArray:Array<RouteRecordRaw>=[
  /**
   *@title 401
   *@author hugh
   *@date 2021-01-22
   */
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/error-page/401.vue')
  },
  /**
   *@title 404
   *@author hugh
   *@date 2021-01-22
   */
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/error-page/404.vue')
  }
];
//示例
addRoutes(routesArray)

export default router
